package com.javalab.recorder.listener;

import java.util.ArrayList;
import java.util.List;

import javax.sound.sampled.Mixer;

import com.javalab.recorder.audio.AudioDevice;
import com.javalab.recorder.config.ApplicationContext;
import com.javalab.recorder.event.OptionsMenuItemClickEvent;
import com.javalab.recorder.ui.OptionsDialog;

public class OptionsMenuItemClickEventListener implements ActionEventListener<OptionsMenuItemClickEvent> {

	@Override
	public void handleActionEvent(OptionsMenuItemClickEvent actionEvent) {
		List<Mixer.Info> mixerInfoList = AudioDevice.getInstance().getTargetMixerInfoList();
		List<String> mixerNameList = new ArrayList<String>();
		for (Mixer.Info mixerInfo : mixerInfoList) {
			mixerNameList.add(mixerInfo.getName());
		}

		OptionsDialog optionsDialog = new OptionsDialog();
		optionsDialog.subscribeEvent(new OptionsDialogOKButtonClickEventListener());
		optionsDialog.setAudioInputDeviceNameList(mixerNameList);
		optionsDialog.setDefaultInputDeviceName(ApplicationContext.getDefaultCapturingMixerName());
		optionsDialog.setVisible(true);
	}

}
